import 'package:business_getx/business_getx.dart';
import 'package:business_getx/pages/controller/controller_test.dart';
import 'package:flutter/material.dart';
import 'package:lib_core/lib_core.dart';
import 'package:lib_ui/lib_ui.dart';
import 'package:lib_ui/utils/ld_font.dart';
import 'package:lib_ui/widget/main_button.dart';

class ControllerTest1Page extends StatefulWidget {
  const ControllerTest1Page({super.key});

  @override
  State<ControllerTest1Page> createState() => _ControllerTest1PageState();
}

class _ControllerTest1PageState extends State<ControllerTest1Page> {


  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: TransparentAppBar(title: 'controller注入'),
      body: SizedBox(
        width: Get.width,
        child: Column(
          mainAxisSize: MainAxisSize.max,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            MainButton(
              text: '给controller的变量赋值为10',
              onClick: () {
                ControllerTest controller;
                try {
                  controller = Get.find<ControllerTest>();
                  '已存在，通过find找到controller'.showInfo();
                } catch (e) {
                  controller = Get.put(ControllerTest());
                  '不存在，通过put找到controller'.showInfo();
                }
                controller.num = 10;
              },
            ),
            MainButton(
              text: '去ControllerText2页面',
              onClick: () {
                // GetRoutes.controllerTest2.push();
                GetRoutes.controllerTest4.push();
              },
            ),
            MainButton(
              text: '检查ControllerTest3改变的值',
              onClick: () {
                ControllerTest controller;
                try {
                  controller = Get.find<ControllerTest>();
                  '已存在，controller num = ${controller.num}'.showInfo();
                } catch (e) {
                  '不存在'.showInfo();
                }
              },
            ),
          ],
        ),
      ),
    );
  }
}
